import 'dart:io';

import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:xiaomi/app/modules/tools/screenAdapter.dart';
import 'package:xiaomi/app/modules/tools/httpClient.dart';
import '../../GoodsDetail/controllers/goods_detail_controller.dart';

class GoodsDetail1View extends GetView {
  @override
  final GoodsDetailController controller = Get.find();

  GoodsDetail1View({super.key});
  @override
  Widget build(BuildContext context) {
    return Obx(() => controller.goodlistmodel.value.sId != null
        ? Container(
            key: controller.k1,
            // height: ScreenAdapter.height(800),
            // color: Colors.green,
            child: Column(
              children: [
                AspectRatio(
                  aspectRatio: 1 / 1,
                  child: Image.network(
                    HttpClient.imageUrl(controller.goodlistmodel.value.pic!),
                    fit: BoxFit.cover,
                  ),
                ),
                // 标题
                Container(
                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                  width: double.infinity,
                  child: Text(
                    controller.goodlistmodel.value.title!,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                ),

                Container(
                  padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                  width: double.infinity,
                  child: Text(
                    controller.goodlistmodel.value.subTitle!,
                    style: TextStyle(fontSize: ScreenAdapter.fontSize(30)),
                  ),
                ),

                Container(
                  padding: EdgeInsets.all(10),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text.rich(
                        TextSpan(
                          children: [
                            TextSpan(
                                text: '价格',
                                style: TextStyle(fontWeight: FontWeight.bold)),
                            TextSpan(
                                text:
                                    '￥${controller.goodlistmodel.value.price!}',
                                style: TextStyle(
                                    color: Colors.red,
                                    fontWeight: FontWeight.bold,
                                    fontSize: ScreenAdapter.fontSize(50)))
                          ],
                        ),
                      ),
                      Text('原价：￥${controller.goodlistmodel.value.oldPrice!}')
                    ],
                  ),
                ),
                Container(
                    child: InkWell(
                        child: Container(
                          margin: EdgeInsets.only(
                              left: ScreenAdapter.width(20),
                              right: ScreenAdapter.width(20),
                              top: ScreenAdapter.width(20)),
                          height: ScreenAdapter.height(100),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text.rich(TextSpan(children: [
                                TextSpan(
                                    text: '已选     ',
                                    style:
                                        TextStyle(fontWeight: FontWeight.bold)),
                                TextSpan(
                                    text: '115 黑色 XL  1件', style: TextStyle()),
                              ])),
                              Icon(
                                Icons.arrow_forward_ios_sharp,
                                color: Colors.grey,
                              ),
                            ],
                          ),
                        ),
                        onTap: () {
                          Get.bottomSheet(GetBuilder(
                              init: controller,
                              builder: (controller) {
                                return Container(
                                    padding: EdgeInsets.only(
                                        left: ScreenAdapter.width(20),
                                        right: ScreenAdapter.width(20)),
                                    color: Colors.white,
                                    width: double.infinity,
                                    height: ScreenAdapter.height(800),
                                    child: Column(
                                      children: controller
                                          .goodlistmodel.value.attr!
                                          .map((v) {
                                        return Container(
                                            margin: EdgeInsets.all(10),
                                            width: double.infinity,
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Text(v.cate!),
                                                Wrap(
                                                  children:
                                                      v.listMap!.map((inside) {
                                                    return InkWell(
                                                      onTap: () {
                                                        controller
                                                            .updateAttrModel(
                                                                v.cate!,
                                                                inside);
                                                      },
                                                      child: Padding(
                                                        padding:
                                                            EdgeInsets.all(5),
                                                        child: Chip(
                                                            color: inside[
                                                                        'selected'] ==
                                                                    true
                                                                ? WidgetStatePropertyAll(
                                                                    Colors.red)
                                                                : WidgetStatePropertyAll(
                                                                    Colors
                                                                        .black12),
                                                            label: Text(inside[
                                                                'title']),
                                                            side: BorderSide(
                                                                style:
                                                                    BorderStyle
                                                                        .none)),
                                                      ),
                                                    );
                                                  }).toList(),
                                                )
                                              ],
                                            ));
                                      }).toList(),
                                    ));
                              }));
                        })),

                Container(
                  child: InkWell(
                    child: Container(
                      margin: EdgeInsets.only(
                          left: ScreenAdapter.width(20),
                          right: ScreenAdapter.width(20),
                          top: ScreenAdapter.width(20)),
                      height: ScreenAdapter.height(100),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text.rich(TextSpan(children: [
                            TextSpan(
                                text: '门店    ',
                                style: TextStyle(fontWeight: FontWeight.bold)),
                            TextSpan(
                                text: '万达之心城店',
                                style: TextStyle(
                                    // color: Colors.red,
                                    // fontWeight: FontWeight.bold,
                                    // fontSize: ScreenAdapter.fontSize(50)
                                    ))
                          ])),
                          Icon(
                            Icons.arrow_forward_ios,
                            color: Colors.grey,
                          ),
                        ],
                      ),
                    ),
                    onTap: () {
                      Get.bottomSheet(Container(
                          padding: EdgeInsets.only(
                              left: ScreenAdapter.width(20),
                              right: ScreenAdapter.width(20)),
                          color: Colors.white,
                          width: double.infinity,
                          height: ScreenAdapter.height(800),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text('配置'),
                              Wrap(
                                spacing: 10,
                                children: [
                                  Chip(
                                    label: Text('你好'),
                                    padding: EdgeInsets.only(
                                        left: ScreenAdapter.width(20),
                                        right: ScreenAdapter.width(20)),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                    label: Text('fdwef'),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                      label: Text('发我恶妇'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('额外付额外'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('恶无非'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('狗头人好'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('还有一会'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                ],
                              ),
                              Text('功能'),
                              Wrap(
                                spacing: 10,
                                children: [
                                  Chip(
                                    label: Text('你好'),
                                    padding: EdgeInsets.only(
                                        left: ScreenAdapter.width(20),
                                        right: ScreenAdapter.width(20)),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                    label: Text('fdwef'),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                      label: Text('发我恶妇'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('额外付额外'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('恶无非'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('狗头人好'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('还有一会'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                ],
                              )
                            ],
                          )));
                    },
                  ),
                ),

                Container(
                  child: InkWell(
                    child: Container(
                      margin: EdgeInsets.only(
                          left: ScreenAdapter.width(20),
                          right: ScreenAdapter.width(20),
                          top: ScreenAdapter.width(20)),
                      height: ScreenAdapter.height(100),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text.rich(TextSpan(children: [
                                TextSpan(
                                    text: '服务     ',
                                    style:
                                        TextStyle(fontWeight: FontWeight.bold))
                              ])),
                              Image.asset('assets/images/service.png'),
                            ],
                          ),
                          Icon(
                            Icons.arrow_forward_ios,
                            color: Colors.grey,
                          ),
                        ],
                      ),
                    ),
                    onTap: () {
                      Get.bottomSheet(Container(
                          padding: EdgeInsets.only(
                              left: ScreenAdapter.width(20),
                              right: ScreenAdapter.width(20)),
                          color: Colors.white,
                          width: double.infinity,
                          height: ScreenAdapter.height(800),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text('配置'),
                              Wrap(
                                spacing: 10,
                                children: [
                                  Chip(
                                    label: Text('你好'),
                                    padding: EdgeInsets.only(
                                        left: ScreenAdapter.width(20),
                                        right: ScreenAdapter.width(20)),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                    label: Text('fdwef'),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                      label: Text('发我恶妇'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('额外付额外'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('恶无非'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('狗头人好'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('还有一会'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                ],
                              ),
                              Text('功能'),
                              Wrap(
                                spacing: 10,
                                children: [
                                  Chip(
                                    label: Text('你好'),
                                    padding: EdgeInsets.only(
                                        left: ScreenAdapter.width(20),
                                        right: ScreenAdapter.width(20)),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                    label: Text('fdwef'),
                                    side: BorderSide(style: BorderStyle.none),
                                  ),
                                  Chip(
                                      label: Text('发我恶妇'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('额外付额外'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('恶无非'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('狗头人好'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                  Chip(
                                      label: Text('还有一会'),
                                      side:
                                          BorderSide(style: BorderStyle.none)),
                                ],
                              )
                            ],
                          )));
                    },
                  ),
                ),
              ],
            ),
          )
        : Container(
            height: ScreenAdapter.height(1000),
            child: CircularProgressIndicator(),
          ));
  }
}
